<?php
require_once 'pages/TMSItemPage.inc';


/**
 * @property TMSPageImageModel $ProductImageModel
 */
class TMSAdminContentPage extends TMSItemPage {	
	
/**
 * @var TMSPageImageModel
 */
	protected $_ioc_page_image_model_;
		
	protected function doImagesAdd($data){
		foreach ($data as $file)
			if (!$file->UploadError())	
				$this->PageImageModel->CreateItem(array('Image'=>$file,'Page'=>$this->ModelItem));
	}
	
	protected function doImagesDelete($data){
		foreach ($data as $id=>$v)
			if ($v)
			$this->PageImageModel->DeleteItem($id);
	}
	
	protected function doImagesUpdate($imagesdesc = array(),$imagesorder = array()){
		foreach ($imagesdesc as $id=>$desc)
			$this->PageImageModel->EditItem($id, array('Description'=>$desc,'OrderNumber'=>isset($imagesorder[$id])?$imagesorder[$id]:null));
	}
	
	public function http_EditImages($addimages = array(),$deleteimages = array(),$imagesdesc = array(),$imagesorder = array()){
		$this->doImagesAdd($addimages);
		$this->doImagesUpdate($imagesdesc,$imagesorder);
		$this->doImagesDelete($deleteimages);
	}		
}